package com.yhl.person.controller;

import com.yhl.person.bean.User;
import com.yhl.person.services.imp.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: yanghl
 * @description: TODO
 * @date: 2024/7/16 17:32
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserServiceImpl userService;

    @PostMapping("/getToken")
    public String getToken(@RequestBody User user){
        System.out.println("user" + user);
        return JwtUtil.createJWT(40000,user);
    }

    @PostMapping("/test")
    public String test(HttpServletRequest request, HttpServletResponse response){
        String token= request.getHeader("Authorization");
        User user = new User();
        user.setName("hand2020");
        user.setPassword("123456");
        if (JwtUtil.isVerify(token,user)){
            return "success";
        }
        return "fail";
    }

    @GetMapping("/getUser")
    public User getUser(){
        return userService.getUserByName("yhl");
    }

}

